package edu.zut.method;

import java.util.Scanner;

public class Demo6 {

    public static void main(String[] args) {
        double ave = getAve();
        System.out.printf("%.2f", ave);
    }

    public static double getAve() {
        Scanner scanner = new Scanner(System.in);
        //num评委人数
        int num;
        do {
            System.out.println("请输入评委人数：");
            num = scanner.nextInt();
        } while (num <= 2);
        //保存所有评委成绩
        double[] scores = new double[num];
        System.out.println("请输入各个评委的成绩，每个成绩之间用空格隔开");
        for (int i = 0; i < num; i++) {
            scores[i] = scanner.nextDouble();
        }
        double sum = getSum(scores);
        sum = sum - getMax(scores) - getMin(scores);
        double ave = sum / (num - 2);
        return ave;
    }

    /**
     * 获取数组的最大值
     *
     * @param arr
     * @return
     */
    public static double getMax(double[] arr) {
        double max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        return max;
    }

    /**
     * 获取数组的最小值
     *
     * @param arr
     * @return
     */
    public static double getMin(double[] arr) {
        double min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (min > arr[i]) {
                min = arr[i];
            }
        }
        return min;
    }

    /**
     * 计算数组中所有元素之和
     *
     * @param arr
     * @return
     */
    public static double getSum(double[] arr) {
        double sum = 0;
        if (arr != null && arr.length > 0) {
            for (double v : arr) {
                sum += v;
            }
        }
        return sum;
    }


}
